<%@page import="com.fractalist.man.constants.ManConstants"%>
<%@page import="com.fractalist.base.core.constants.SystemConstants"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	pageContext.setAttribute("baseweburl",
			SystemConstants.UPLOAD_WEB_URL);
%>
<%
	pageContext.setAttribute("questBasetypeMap",
			ManConstants.QUEST_BASETYPE_MAP);
	pageContext.setAttribute("questTypeMap",
			ManConstants.QUEST_TYPE_MAP);
	pageContext.setAttribute("userGenderMap",
			ManConstants.USER_GENDER_MAP);
	pageContext.setAttribute("userTypeMap", ManConstants.USER_TYPE_MAP);
	Map<String,Object> quest = (Map<String,Object>)request.getAttribute("quest");
	if(quest !=null){
		String questUserType = quest.get("questUserType")+"";
		String[] questUserTypeArr = questUserType.split("_");
		pageContext.setAttribute("questUserTypeFir", questUserTypeArr[0]);
		if(questUserTypeArr.length > 1){
			pageContext.setAttribute("questUserTypeSec", Integer.valueOf(questUserTypeArr[1]));
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>任务</title>
<link rel="stylesheet" href="${ctx }/css/styles.css" type="text/css" />
<script type="text/javascript" src="${ctx }/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery.form.js"></script>
<jsp:include page="/common/jscalendar.jsp"></jsp:include>
</head>
<body style="overflow-y: scroll;">
	<script>
		var baseweburl = "${baseweburl}";

		function createFm() {
			var type = $("#type").val();
			var title = $("#title").val();
			var desc = $("#desc").val();
			var questProcess = $("#questProcess").val();

			var userType = $("#userType").val();
			var userTypeGender = $("#userTypeGender").val();
			var userTypeType = $("#userTypeType").val();
			var score = $("#score").val();
			var scoreRuleId = $("#scoreRuleId").val();
			if (type == "") {
				alert("请输入任务类型");
				return;
			}
			if (title == "") {
				alert("请输入任务标题");
				return;
			}
			if (desc == "") {
				alert("请输入任务描述");
				return;
			}
			if (questProcess == "") {
				alert("请输入任务进度数");
				return;
			}
			if (userType == "") {
				alert("请输入任务针对用户类型");
				return;
			}
			if (score == "") {
				alert("请输入完成积分奖励");
				return;
			}
			if (userType == "usertype") {
				userType += "_" + userTypeType;
			}
			if (userType == "gender") {
				userType += "_" + userTypeGender;
			}

			$.post("${ctx}/manager/createQuest.action", {
				title : title,
				type : type,
				desc : desc,
				questProcess : questProcess,
				userType : userType,
				score : score,
				scoreRuleId : scoreRuleId,
				questId : $("#questId").val()
			}, function(data) {
				location.href = "${ctx}/manage/viewQuestPage.action";
			})
		}
		
		function changeTypes(){
			var userType = $("#userType").val();
			if(userType == "gender"){
				 $('#userTypeGender').show();
				 $('#userTypeType').hide();
			}
			if(userType == "usertype"){
				 $('#userTypeGender').hide();
				 $('#userTypeType').show();
			}
			if(userType == "all"){
				 $('#userTypeGender').hide();
				 $('#userTypeType').hide();
			}
		}
	</script>
	<div id="wrapper">
		<div id="content_wrap">
			<div class="tabs_content">
				<div class="active_tab" id="tab1"></div>
				<div id="table_wrapper" style="width: 100%; overflow: auto;">
					<table class="table" cellpadding="0" cellspacing="0">
						<input type="hidden" name="questId" id="questId" value="${quest.id }" />
						<tr>
							<td>任务类型</td>
							<td><select id="type">
									<c:forEach items="${questBasetypeMap}" var="entry">
										<option value="${entry.key }"
											<c:if test="${quest.questSiteType == entry.key }">selected=selected</c:if>>${entry.value
											}</option>
									</c:forEach>
							</select></td>
						</tr>
						<tr>
							<td>任务标题</td>
							<td><input id="title" type="text"
								value="${quest.questName }" /></td>
						</tr>
						<tr>
							<td>任务描述</td>
							<td><input id="desc" type="text" value="${quest.questDesc }" /></td>
						</tr>
						<tr>
							<td>任务进度数</td>
							<td><input id="questProcess" type="text"
								value="${quest.questProcessCount }" /></td>
						</tr>
						<tr>
							<td>任务针对用户类型</td>
							<td><select id="userType" onchange="changeTypes()">
									<c:forEach items="${questTypeMap}" var="entry">
										<option value="${entry.key }"
											<c:if test="${questUserTypeFir == entry.key }">selected=selected</c:if>>${entry.value
											}</option>
									</c:forEach>

							</select> <select id="userTypeGender" style="display: none;">
									<c:forEach items="${userGenderMap}" var="entry">
										<option value="${entry.key }"
											<c:if test="${questUserTypeFir == 'gender' && questUserTypeSec - entry.key == 0 }">selected=selected</c:if>>${entry.value
											}</option>
									</c:forEach>
							</select> <select id="userTypeType" style="display: none;">
									<c:forEach items="${userTypeMap}" var="entry">
										<option value="${entry.key }"
											<c:if test="${questUserTypeFir == 'usertype' && questUserTypeSec - entry.key == 0 }">selected=selected</c:if>>${entry.value
											}</option>
									</c:forEach>
							</select></td>
						</tr>
						<tr>
							<td>完成积分奖励</td>
							<td><input id="score" type="text" value="${quest.score }" />
								<input id="scoreRuleId" type="hidden"
								value="${quest.scoreRuleId }" /></td>
						</tr>
						<tr>
							<td></td>
							<td><input type="button" value="提交" onclick="createFm();" /></td>
						</tr>
					</table>
				</div>
				<script>
					<c:if test="${questUserTypeFir == 'usertype'}">
					$("#userTypeType").show();
					</c:if>
					<c:if test="${questUserTypeFir == 'gender'}">
					$("#userTypeGender").show();
					</c:if>
				</script>
			</div>
		</div>
	</div>
	</div>
</body>
</html>

